package com.cbd.upload;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;


@Controller
public class uploadAacion {
	@RequestMapping("cbd/landlady/upload")
	public @ResponseBody Map<Object, Object> upload(@RequestParam("myFile") CommonsMultipartFile file,HttpServletRequest req,HttpServletResponse res){
		String fileName=file.getOriginalFilename();//
		long fileSize=file.getSize()/1024+1;
		//System.out.println(fileSize);
		String path=req.getSession().getServletContext().getRealPath("upload");
		String msg=null;
		String err=null;
		try {
			file.getFileItem().write(new File(path + File.separator + fileName));
			msg="上传文件成功";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			err=e.getMessage();
		}
		Map<Object, Object> map=new HashMap<Object, Object>();
		map.put("msg", msg);
		map.put("err", err);
		map.put("filePath","upload/"+fileName);
		return map;
	}
}
   